package com.lv.hechuang.utils;

import android.content.Context;
import android.content.res.Resources;
import android.widget.Toast;

import com.lv.hechuang.app.App;


/**
 * Toast工具类
 * Created by Administrator on 2016/7/25.
 */
public class ToastUtils {

    private static Toast toast;

    public static void showMessage(String message) {
        if (null == toast) {
            toast = Toast.makeText(App.instance().getApplicationContext(), message, Toast.LENGTH_SHORT);
            toast.show();
            return;
        }
        toast.cancel();
        toast = Toast.makeText(App.instance().getApplicationContext(), message, Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void showMessage(int resID) {
        String message = "";
        Context applicationContext = App.instance().getApplicationContext();
        if (resID > 0) {
            try {
                message = applicationContext.getResources().getString(resID);
            } catch (Resources.NotFoundException e) {
                e.printStackTrace();
            }
        }
        if (null == toast) {
            toast = Toast.makeText(applicationContext, message, Toast.LENGTH_SHORT);
            toast.show();
            return;
        }
        toast.cancel();
        toast = Toast.makeText(applicationContext, message, Toast.LENGTH_SHORT);
        toast.show();
    }
}
